/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the implentation for the lookup dialog
 * This dialog pops up when the application is attempting
 * to lookup a hostname the user supplied it. It allows
 * the user to watch see the app doing something */

#include "lookupdialog.h"
#include "ui_lookupdialog.h"

/* LookupDialog constructor:
 * Takes a string which is the address
 * that is being connected to */
LookupDialog::LookupDialog(const QString& addr, QWidget *parent) :
    QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint),
    ui(new Ui::LookupDialog)
{
    //Initialize UI elements
    ui->setupUi(this);

    //Store address and set start text
    myAddress = addr;
    ui->labelStatus->setText( "Looking up \"" + myAddress + "\"..." );
}

/* LookupDialog destructor */
LookupDialog::~LookupDialog()
{
    delete ui;
}

/* foundHost slot:
 * Activated by the socket's hostFound()
 * signal, this slot changes to the text to
 * notify the user of the socket's new state */
void LookupDialog::foundHost()
{
    ui->labelStatus->setText( "Connecting to \"" + myAddress + "\"..." );
}

/* connectionEstablished slot:
 * Activated by the socket's connected()
 * signal, this slot changes to the text to
 * notify the user of the socket's new state
 * and closes itself because the connecting is over */
void LookupDialog::connectionEstablished()
{
    ui->labelStatus->setText( "Connected!" );
    this->close();
}

/* errorOccured slot:
 * This is connected to the socket's
 * error signal. It just closes the dialog
 * because the connecting process is over */
void LookupDialog::errorOccured( QAbstractSocket::SocketError e )
{
    this->close();
}

/* on_buttonCancel_clicked() slot:
 * This is called when the cancel button is
 * clicked. It emits a signal to tell the
 * detail tab to abort the socket connection */
void LookupDialog::on_buttonCancel_clicked()
{
    emit cancelled();
    this->close();
}
